package com.twu.biblioteca.command;

import com.twu.biblioteca.model.Book;
import com.twu.biblioteca.model.Borrowable;
import com.twu.biblioteca.domain.Library;

import java.util.List;

public class ListBooksCommand extends Command {
    private Library library;

    public ListBooksCommand(Library library) {
        this.library = library;
    }

    @Override
    public String execute() {
        String listBooks = "list books\n";
        List<Borrowable> books = library.getAllBooks();
        for (Borrowable borrowable : books) {
            Book book = (Book) borrowable;
            String listBook = book.getId() + "\t" + book.getName() + "\t" + book.getAuthor() + "\t" + book.getYearPublished() + "\n";
            listBooks += listBook;
        }
        return listBooks;
    }
}
